namespace GuiLabs.Undo {
	public class TransactionBase : ITransaction {
		#region ctors

		public TransactionBase(ActionManager am, bool isDelayed)
			: this(am) {
			IsDelayed = isDelayed;
		}

		public TransactionBase(ActionManager am)
			: this() {
			ActionManager = am;
			if (am != null) {
				am.OpenTransaction(this);
			}
		}

		public TransactionBase() {
			IsDelayed = true;
		}

		#endregion

		public ActionManager ActionManager { get; private set; }
		public bool IsDelayed { get; set; }

		protected IMultiAction mAccumulatingAction;
		public IMultiAction AccumulatingAction {
			get {
				return mAccumulatingAction;
			}
		}

		public virtual void Commit() {
			if (ActionManager != null) {
				ActionManager.CommitTransaction();
			}
		}

		public virtual void Rollback() {
			if (ActionManager != null) {
				ActionManager.RollBackTransaction();
			}
		}

		public void Dispose() {
			Commit();
		}
	}
}
